home *** CD-ROM | disk | FTP | other *** search
- <?php
- /*
- ** $Id: tools_restore.php,v 1.7 2005/04/05 11:05:20 hmailserver Exp $
- **
- ** hMailServer - Web interface
- **
- ** File formatted using TAB size 4
- **
- ** Get hMailserver at http://www.hmailserver.com
- **
- ** Author: Steen Rab°l <srabol@mail.tele.dk>
- ** Copyright (c) 2004, Steen Rab°l <srabol@mail.tele.dk>
- **
- ** This program is free software; you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation; either version 2 of the License, or
- ** (at your option) any later version.
- **
- ** You may not change or alter any portion of this comment or credits
- ** of supporting developers from this source code or any supporting
- ** source code which is considered copyrighted (c) material of the
- ** original comment or credit authors.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program; if not, write to the Free Software
- ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- **
- */
-
- if (!eregi("index.php", $_SERVER['PHP_SELF']))
- {
- die ("You can't access this file directly...");
- }
-
- if (hmailGetAdminLevel() != 2)
- hmailHackingAttemp();
-
-
- require_once("include/minixml/minixml.inc.php");
- $function = hmailGetVar("function");
-
- if($function == "dorestore")
- {
- $dodomains = hmailGetVar("dodomains","");
- $doaccounts = hmailGetVar("doaccounts","");
- $doaliases = hmailGetVar("doaliases","");
- $dodistributionlists = hmailGetVar("dodistributionlists","");
- $dodistrecipients = hmailGetVar("dodistrecipients","");
- $dosettings = hmailGetVar("dosettings","");
- $filename = hmailGetVar("filename","");
- $destfilename = $hmail_config['temppath'] . $filename;
- $output = array();
-
- $xmlDoc = new MiniXMLDoc();
- $xmlDoc->fromFile($destfilename);
- $xmlRoot = &$xmlDoc->getRoot();
-
- if($dodomains == strtolower("on"))
- {
- $xmlroot_Domains = &$xmlRoot->getElement("domains");
- if(is_object($xmlroot_Domains))
- {
- $restoreoptions = array();
-
- if($doaccounts == strtolower("on"))
- $restoreoptions["accounts"] = true;
- else
- $restoreoptions["accounts"] = false;
-
- if($doaliases == strtolower("on"))
- $restoreoptions["aliases"] = true;
- else
- $restoreoptions["aliases"] = false;
-
- if($dodistributionlists == strtolower("on"))
- $restoreoptions["distributionlists"] = true;
- else
- $restoreoptions["distributionlists"] = false;
-
- if($dodistrecipients == strtolower("on"))
- $restoreoptions["distrecipients"] = true;
- else
- $restoreoptions["distrecipients"] = false;
-
- RestoreDomains($xmlroot_Domains,$restoreoptions);
- }
- else
- {
- $output[] = array("log"=>"Restore: Domains node not found in XML file '$filename'");
- }
- }
-
- if($dosettings == strtolower("on"))
- {
- $xmlroot_settings = &$xmlRoot->getElement("settings");
- if(is_object($xmlroot_settings))
- {
- RestoreSettings($xmlroot_settings);
- }
- }
- $hmailSmarty->assign("output",$output);
- $hmailSmarty->assign("pagecontent",$hmailSmarty->fetch('tools_restore_complete.tpl'));
- }
- else if ($function == "dorestore_checkfile")
- {
- $filename = (isset($_REQUEST['filename']) ? $_REQUEST['filename'] : "");
- $destfilename = $hmail_config['temppath'] . $_FILES['filename']['name'];
-
- if (move_uploaded_file($_FILES['filename']['tmp_name'], $destfilename))
- {
- $xmlDoc = new MiniXMLDoc();
- $xmlDoc->fromFile($destfilename);
- $xmlRoot = &$xmlDoc->getRoot();
-
- $xmlroot_Domains = &$xmlRoot->getElement("domains");
- if(is_object($xmlroot_Domains))
- {
- $hmailSmarty->assign("hasdomains",1);
- }
-
- $xmlroot_Settings = &$xmlRoot->getElement("settings");
- if(is_object($xmlroot_Settings))
- {
- $hmailSmarty->assign("hassettings",1);
- }
- $hmailSmarty->assign("filename",$_FILES['filename']['name']);
- $hmailSmarty->assign("pagecontent", $hmailSmarty->fetch('tools_restore_checkfile.tpl'));
- }
- else
- {
- $hmailSmarty->assign("error", hmailGetLocaleText("faild _to_upload_file"));
- $hmailSmarty->assign("pagecontent", $hmailSmarty->fetch('tools_restore_checkfile.tpl'));
- }
- }
- else
- {
- $hmailSmarty->assign("pagecontent", $hmailSmarty->fetch('tools_restore.tpl'));
- }
-
- function RestoreDomains(&$p_xmlroot,$p_options)
- {
- global $obBaseApp;
- AddToLog("Start restore, found " . $p_xmlroot->attribute("count") . " domains");
- $xmldomains = &$p_xmlroot->getAllChildren();
- if(is_array($xmldomains))
- {
- foreach($xmldomains as $xmldomain)
- {
- $xmldomain_name = &$xmldomain->getElement("name");
- $domainname = trim($xmldomain_name->text());
- AddToLog("Restore domain " . $xmldomain->attribute("id") . " '" . $domainname . "'" );
- $obDomains = $obBaseApp->Domains();
- $obDomains->Refresh();
- if(is_object($obDomains))
- {
- $obDomain = @$obDomains->ItemByName($domainname);
- if(!$obDomain)
- {
- $obDomain = $obDomains->Add();
- AddToLog("Create domain " . " " . $xmldomain_name->text());
- }
- else
- {
- AddToLog("Update domain " . " " . $xmldomain_name->text());
- }
-
- $obDomain->Name = $xmldomain_name->text();
- $xmldomain_active = &$xmldomain->getElement("active");
- $active = trim($xmldomain_active->text());
- if(empty($active) || $active == 0)
- $active = false;
- else
- $active = true;
-
- $obDomain->Active = $active;
-
- $xmldomain_postmaster = &$xmldomain->getElement("postmaster");
- $obDomain->Postmaster = trim($xmldomain_postmaster->text());
- $obDomain->Save();
- $obDomains->Refresh();
-
- if($p_options["accounts"])
- {
- $xmlaccounts = &$xmldomain->getElement("accounts");
- if(is_object($xmlaccounts))
- RestoreAccounts($xmlaccounts,$obDomain,$p_options);
- }
-
- if($p_options["aliases"])
- {
- $xmlaliases = &$xmldomain->getElement("aliases");
- if(is_object($xmlaliases))
- RestoreAliases($xmlaliases,$obDomain);
- }
-
- if($p_options["distributionlists"])
- {
- $xmldistributionlists = &$xmldomain->getElement("distributionlists");
- if(is_object($xmldistributionlists))
- RestoreDistributionLists($xmldistributionlists,$obDomain,$p_options);
- }
- }
- else
- {
- AddToLog("Faild to get Domain collection from server");
- }
- }
- }
- else
- {
- AddToLog("Faild to get domain information from file");
- }
- }
-
- function AddToLog($p_message)
- {
- global $output;
- $output[] = array("log" => $p_message);
- }
-
- function RestoreAccounts(&$p_xmlroot, &$p_domain, &$p_options)
- {
- $obAccounts = $p_domain->Accounts();
- AddToLog("Start restore, found " . $p_xmlroot->attribute("count") . " accounts");
- $xmldaccounts = &$p_xmlroot->getAllChildren();
- if(is_array($xmldaccounts))
- {
- foreach($xmldaccounts as $xmlaccount)
- {
- $xmlaccount_address_elm = &$xmlaccount->getElement("address");
- AddToLog("Restore account : " . $xmlaccount_address_elm->text());
- $obAccount = @$obAccounts->ItemByAddress(trim($xmlaccount_address_elm->text()));
-
- if(!$obAccount)
- $obAccount = $obAccounts->Add();
-
- $xmlaccount_active = &$xmlaccount->getElement("active");
- $active = trim($xmlaccount_active->text());
- if(empty($active) || $active == 0)
- $active = false;
- else
- $active = true;
-
- $obAccount->Active = $active;
- $obAccount->Address = trim($xmlaccount_address_elm->text());
- $xmlaccount_addomain_elm = &$xmlaccount->getElement("addomain");
- $obAccount->ADDomain = $xmlaccount_addomain_elm->text();
- $xmlaccount_isad_elm = &$xmlaccount->getElement("isad");
- $obAccount->IsAd = $xmlaccount_isad_elm->text() == "" ? 0 : 1;
- $xmlaccount_password_elm = &$xmlaccount->getElement("password");
- $obaccount->Password = $xmlaccount_password_elm->text();
- $xmlaccount_adusername_elm = &$xmlaccount->getElement("adusername");
- $obAccount->ADUsername = $xmlaccount_adusername_elm->text();
- $xmlaccount_maxsize_elm = &$xmlaccount->getElement("maxsize");
- $obaccount->MaxSize = $xmlaccount_maxsize_elm->text();
- $xmlaccount_vacationmessageison_elm = &$xmlaccount->getElement("vacationmessageison");
- $obAccount->VacationMessageIsOn = $xmlaccount_vacationmessageison_elm->text() == "" ? 0 : 1;
- $xmlaccount_vacationmessage_elm = &$xmlaccount->getElement("vacationmessage");
- $obAccount->VacationMessage = $xmlaccount_vacationmessage_elm->text();
- $xmlaccount_vacationsubject_elm = &$xmlaccount->getElement("vacationsubject");
- if($xmlaccount_vacationsubject_elm)
- {
- $obAccount->VacationSubject = $xmlaccount_vacationsubject_elm->text();
- }
- $obAccount->Save();
-
- }
- }
-
- }
- function RestoreAliases(&$p_xmlroot, &$p_domain)
- {
- $xmlaliases = &$p_xmlroot->getAllChildren();
- AddToLog("Restore aliases");
- if(is_array($xmlaliases))
- {
- $obAliases = $p_domain->Aliases();
- foreach($xmlaliases as $xmlalias)
- {
- $elm = $xmlalias->getElement("name");
- $obAlias = @$obAliases->ItemByName($elm->text());
- if(!$obAlias)
- $obAlias = $obAliases->Add();
-
- $obAlias->Name = $elm->text();
- $elm = $xmlalias->getElement("active");
- $obAlias->Active = ($elm->text() == "" ? 0 : 1);
- $obAlias->DomainID = $p_domain->ID;
- $elm = $xmlalias->getElement("type");
- $obAlias->Type = ($elm->text() == 0 ? 0 : $elm->text());
- $elm = $xmlalias->getElement("value");
- $obAlias->Value = $elm->text();
- $obAlias->Save();
- }
- }
- }
-
- function RestoreDistributionLists(&$p_xmlroot,&$p_domain,$p_options)
- {
- AddToLog("Restore distributionlists");
- $xmldistributionlists = &$p_xmlroot->getAllChildren();
- if(is_array($xmldistributionlists))
- {
- $obDistributionLists = $p_domain->DistributionLists();
- foreach($xmldistributionlists as $xmldistributionlist)
- {
- $elm = $xmldistributionlist->getElement("address");
- $obDistributionList = @$obDistributionLists->ItemByAddress($elm->text());
- if(!$obDistributionList)
- $obDistributionList = $obDistributionLists->Add();
-
- $obDistributionList->Address = $elm->text();
- $elm = $xmldistributionlist->getElement("active");
- $obDistributionList->Active = ($elm->text() == "" ? 0 : 1);
- $elm = $xmldistributionlist->getElement("requiresmtpauth");
- $obDistributionList->RequireSMTPAuth = ($elm->text() == "" ? 0 : 1);
- $elm = $xmldistributionlist->getElement("requiresenderaddress");
- $obDistributionList->RequireSenderAddress = $elm->text();
- $obDistributionList->Save();
-
- if($p_options["distrecipients"])
- {
- $xmlrecip = $xmldistributionlist->getElement("recipients");
- if($xmlrecip)
- {
- if(is_object($xmlrecip))
- {
- $obRecipients = $obDistributionList->Recipients();
- $xmlrecipients = $xmlrecip->getAllChildren();
-
- foreach($xmlrecipients as $xmlrecipient)
- {
- $obRecipient = $obRecipients->Add();
- $elm = $xmlrecipient->getElement("recipientaddress");
- $obRecipient->RecipientAddress = $elm->text();
- $obRecipient->Save();
- }
- }
- }
- }
- }
- }
- }
-
- function RestoreSettings($p_xmlroot)
- {
- global $obBaseApp;
- AddToLog("Restore settings");
- $obSettings = $obBaseApp->Settings();
- $xmlsettings = &$p_xmlroot;
-
- $elm = $xmlsettings->getElement("POP3Port");
- $obSettings->POP3Port = $elm->text();
- $elm = $xmlsettings->getElement("SMTPPort");
- $obSettings->SMTPPort = $elm->text();
- $elm = $xmlsettings->getElement("MaxSMTPConnections");
- $obSettings->MaxSMTPConnections = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlsettings->getElement("MaxPOP3Connections");
- $obSettings->MaxPOP3Connections = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlsettings->getElement("MirrorEMailAddress");
- $obSettings->MirrorEMailAddress = $elm->text();
- $elm = $xmlsettings->getElement("AllowSMTPAuthPlain");
- $obSettings->AllowSMTPAuthPlain = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlsettings->getElement("DenyMailFromNull");
- $obSettings->DenyMailFromNull = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlsettings->getElement("TarpitDelay");
- $obSettings->TarpitDelay = $elm->text();
- $elm = $xmlsettings->getElement("TarpitCount");
- $obSettings->TarpitCount = $elm->text();
- $elm = $xmlsettings->getElement("SMTPNoOfTries");
- $obSettings->SMTPNoOfTries = $elm->text();
- $elm = $xmlsettings->getElement("SMTPMinutesBetweenTry");
- $obSettings->SMTPMinutesBetweenTry = $elm->text();
- $elm = $xmlsettings->getElement("IMAPPort");
- $obSettings->IMAPPort = $elm->text();
- $elm = $xmlsettings->getElement("SMTPRelayer");
- $obSettings->SMTPRelayer = $elm->text();
- $elm = $xmlsettings->getElement("WelcomeSMTP");
- $obSettings->WelcomeSMTP = $elm->text();
- $elm = $xmlsettings->getElement("WelcomePOP3");
- $obSettings->WelcomePOP3 = $elm->text();
- $elm = $xmlsettings->getElement("WelcomeIMAP");
- $obSettings->WelcomeIMAP = $elm->text();
- $elm = $xmlsettings->getElement("ServiceSMTP");
- $obSettings->ServiceSMTP = $elm->text();
- $elm = $xmlsettings->getElement("ServicePOP3");
- $obSettings->ServicePOP3 = $elm->text();
- $elm = $xmlsettings->getElement("ServiceIMAP");
- $obSettings->ServiceIMAP = $elm->text();
- $elm = $xmlsettings->getElement("MaxDeliveryThreads");
- $obSettings->MaxDeliveryThreads = $elm->text();
- $elm = $xmlsettings->getElement("SendStatistics");
- $obSettings->SendStatistics = $elm->text();
- $elm = $xmlsettings->getElement("HostName");
- $obSettings->HostName = $elm->text();
- $elm = $xmlsettings->getElement("SMTPRelayerRequiresAuthentication");
- $obSettings->SMTPRelayerRequiresAuthentication = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlsettings->getElement("SMTPRelayerUsername");
- $obSettings->SMTPRelayerUsername = $elm->text();
- $elm = $xmlsettings->getElement("SMTPRelayerPort");
- $obSettings->SMTPRelayerPort = $elm->text();
-
- // Routes
- $xmlroote_routes = $xmlsettings->getElement("routes");
- if($xmlroote_routes)
- {
- AddToLog("Restore routes");
- $xmlroutes = &$xmlroote_routes->getAllChildren();
- if(is_array($xmlroutes))
- {
- $obRoutes = $obSettings->Routes();
- foreach($xmlroutes as $xmlroute)
- {
- $obRoute = $obRoutes->Add();
- $elm = $xmlroute->getElement("DomainName");
- $obRoute->DomainName = $elm->text();
- $elm = $xmlroute->getElement("TargetSMTPHost");
- $obRoute->TargetSMTPHost = $elm->text();
- $elm = $xmlroute->getElement("TargetSMTPPort");
- $obRoute->TargetSMTPPort = $elm->text();
- $elm = $xmlroute->getElement("NumberOfTries");
- $obRoute->NumberOfTries = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroute->getElement("MinutesBetweenTry");
- $obRoute->MinutesBetweenTry = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroute->getElement("AllAddresses");
- $obRoute->AllAddresses = $elm->text();
- $elm = $xmlroute->getElement("RelayerRequiresAuth");
- $obRoute->RelayerRequiresAuth = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroute->getElement("RelayerAuthUsername");
- $obRoute->RelayerAuthUsername = $elm->text();
- $elm = $xmlroute->getElement("TreatSecurityAsLocalDomain");
- $obRoute->TreatSecurityAsLocalDomain = $elm->text();
- $obRoute->Save();
-
- // Addresses
- $xmlroot_routes_adr = $xmlroute->getElement("routeaddresses");
- if($xmlroot_routes_adr)
- {
- $xmlroutesaddresses = &$xmlroot_routes_adr->getAllChildren();
- if(is_array($xmlroutesaddresses))
- {
- $obAddresses = $obRoute->Addresses();
- foreach($xmlroutesaddresses as $xmlroutesaddress)
- {
- $obAddress = $obAddresses->Add();
- $elm = $xmlroutesaddress->getElement("Address");
- $obAddress->Address = $elm->text();
- $obAddress->RouteID = $obRoute->ID;
- $obAddress->Save();
- }
- }
- }
- }
- }
- }
-
- // IP Ranges
- $xmlroot_ipranges = &$xmlsettings->getElement("ipranges");
- if($xmlroot_ipranges)
- {
- $xmlranges = &$xmlroot_ipranges->getAllChildren();
- if(is_array($xmlranges))
- {
- AddToLog("Restore IP Ranges");
- $obSecurityRanges = $obSettings->SecurityRanges();
- foreach($xmlranges as $xmlrange)
- {
- $obRange = $obSecurityRanges->Add();
- $elm = $xmlrange->getElement("LowerIP");
- $obRange->LowerIP = $elm->text();
- $elm = $xmlrange->getElement("UpperIP");
- $obRange->UpperIP = $elm->text();
- $elm = $xmlrange->getElement("AllowSMTPConnections");
- $obRange->AllowSMTPConnections = $elm->text();
- $elm = $xmlrange->getElement("AllowPOP3Connections");
- $obRange->AllowPOP3Connections = $elm->text();
- $elm = $xmlrange->getElement("Priority");
- $obRange->Priority = $elm->text();
- $elm = $xmlrange->getElement("AllowIMAPConnections");
- $obRange->AllowIMAPConnections = $elm->text();
- $elm = $xmlrange->getElement("Name");
- $obRange->Name = $elm->text();
- $elm = $xmlrange->getElement("RequireAuthForDeliveryToLocal");
- $obRange->RequireAuthForDeliveryToLocal = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlrange->getElement("RequireAuthForDeliveryToRemote");
- $obRange->RequireAuthForDeliveryToRemote = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlrange->getElement("AllowDeliveryFromLocalToLocal");
- $obRange->AllowDeliveryFromLocalToLocal = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlrange->getElement("AllowDeliveryFromLocalToRemote");
- $obRange->AllowDeliveryFromLocalToRemote = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlrange->getElement("AllowDeliveryFromRemoteToLocal");
- $obRange->AllowDeliveryFromRemoteToLocal = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlrange->getElement("AllowDeliveryFromRemoteToRemote");
- $obRange->AllowDeliveryFromRemoteToRemote = ($elm->text() == "" ? 0 : $elm->text());
- $obRange->Save();
- }
- }
- }
-
- // Logging
- $xmlroot_logging = &$xmlsettings->getElement("logging");
- if($xmlroot_logging)
- {
- AddToLog("Restore logging");
- $obLogging = $obSettings->Logging();
- $elm = $xmlroot_logging->getElement("Enabled");
- $obLogging->Enabled = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroot_logging->getElement("LogSMTP");
- $obLogging->LogSMTP = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroot_logging->getElement("LogPOP3");
- $obLogging->LogPOP3 = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroot_logging->getElement("LogTCPIP");
- $obLogging->LogTCPIP = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroot_logging->getElement("LogApplication");
- $obLogging->LogApplication = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroot_logging->getElement("Device");
- $obLogging->Device = $elm->text();
- $elm = $xmlroot_logging->getElement("LogFormat");
- $obLogging->LogFormat = $elm->text();
- $elm = $xmlroot_logging->getElement("LogDebug");
- $obLogging->LogDebug = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroot_logging->getElement("LogIMAP");
- $obLogging->LogIMAP = ($elm->text() == "" ? 0 : $elm->text());
- }
- // Antivirus
- $xmlroot_antivirus = &$xmlsettings->getElement("antivirus");
- if($xmlroot_antivirus)
- {
- AddToLog("Restore antivirus");
- $obAntivirus = $obSettings->AntiVirus();
- $elm = $xmlroot_antivirus->getElement("ClamWinEnabled");
- $obAntivirus->ClamWinEnabled = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroot_antivirus->getElement("ClamWinExecutable");
- $obAntivirus->ClamWinExecutable = $elm->text();
- $elm = $xmlroot_antivirus->getElement("ClamWinDBFolder");
- $obAntivirus->ClamWinDBFolder = $elm->text();
- $elm = $xmlroot_antivirus->getElement("Action");
- $obAntivirus->Action = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroot_antivirus->getElement("NotifyReceiver");
- $obAntivirus->NotifyReceiver = ($elm->text() == "" ? 0 : $elm->text());
- $elm = $xmlroot_antivirus->getElement("NotifySender");
- $obAntivirus->NotifySender = ($elm->text() == "" ? 0 : $elm->text());
- }
- }
- ?>